<?php
class AdminusermanageController extends Controller {
	public function index() {
		$smaryt = $this->getSmarty ();
		
		// 如果不是post方式的提交，直接转向
		if (! CommonBase::isPost ()) {
			$this->smarty->display ( "admin/users/adminusermanage.tpl" );
			return;
		}
		
		$user = $_SESSION ['aduser'];
		
	
		// require_once SERVICE . DS . 'admin' . DS . 'UsersService.class.php';
		// $userService = new UsersService ( $this->getDB () );
		
		// $user = $userService->getUserInfoByID ( $suser->userid );
		
		$this->smarty->display ( "admin/users/adminusermanage.tpl" );
	}
	public function getMsg() {
		$smaryt = $this->getSmarty ();
		$user = $_SESSION ['aduser'];
		if (empty ( $user->user_image )) {
			$user->user_image = "user-iocn.gif";
		}
		echo json_encode ( $user );
	}
	public function modify() {
		$smaryt = $this->getSmarty ();
		require_once SERVICE . DS . 'admin' . DS . 'AdminuserService.class.php';
		$userService = new AdminuserService ( $this->getDB () );
		$password = $_POST ["passwd"];
		$user = $_SESSION ['aduser'];
		if ($password != $user->passwd) {
			$password = MD5 ( $password );
		}
		$input_data = array (
				'user_name' => $_POST ["user_name"],
				'mobile' => $_POST ["mobile"],
				'email' => $_POST ["email"],
				'user_image' => $_POST ["user_image"],
				'passwd' => $password 
		);
		$input_condition = array (
				'id' => $_POST ["id"] 
		);
		
		$user_id = $userService->edit ( $input_data, $input_condition );
		if ($user_id > 0) {
			$newuser = $userService->getAdminByID ( $_POST ["id"] );
			$_SESSION ['aduser'] = $newuser;
		}
		echo $user_id;
	}
}